package com.lingyun.generator.utils;

import java.util.StringTokenizer;

/**
 * Created by bain.wang on 2016/1/11.
 */
public class NameUtil {

    public static String getJavaName(String field) {

        StringTokenizer stringTokenizer = new StringTokenizer(field, "_");
        StringBuffer stringBuffer = new StringBuffer();
        int idx = 0;
        while (stringTokenizer.hasMoreTokens()) {
            String tmp = stringTokenizer.nextToken();
            if (idx == 0) {
                stringBuffer.append(tmp);
            } else {
                if (tmp.length() == 1) {
                    stringBuffer.append(tmp.toUpperCase());
                } else {
                    String tmp1 = tmp.toUpperCase();
                    String xyz = tmp1.substring(0, 1) + tmp.substring(1);

                    stringBuffer.append(xyz);
                }

            }
            idx++;
        }
        return stringBuffer.toString();
    }

    public static String getBigJavaName(String field) {
        StringTokenizer stringTokenizer = new StringTokenizer(field, "_");
        StringBuffer stringBuffer = new StringBuffer();
        int idx = 0;
        while (stringTokenizer.hasMoreTokens()) {
            String tmp = stringTokenizer.nextToken();

            if (tmp.length() == 1) {
                stringBuffer.append(tmp.toUpperCase());
            } else {
                String tmp1 = tmp.toUpperCase();
                String xyz = tmp1.substring(0, 1) + tmp.substring(1);

                stringBuffer.append(xyz);
            }


            idx++;
        }
        return stringBuffer.toString();
    }

    public static void main(String args[]) {
        System.out.println(NameUtil.getBigJavaName("create_time"));
        System.out.println(NameUtil.getBigJavaName("create_x_time"));

    }

}
